<%@ page import="org.bson.Document" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.mongodb.BasicDBObject" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page import="javax.print.Doc" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加学生</title>
</head>
<body>
<%
    MongoClient conn = MongoClients.create("mongodb://g08:" + URLEncoder.encode("abc@8") + "@mongo.zhledu.cn:27017/g08");
    MongoDatabase g08 = conn.getDatabase("g08");
    MongoCollection<Document> student = g08.getCollection("student");

    /**
     * db.student.aggregate([
     * {"$match":{"sno":{"$gt":1}}},
     * {"$sort":{"sno":1}},
     * {"$limit":1}
     * ])
     */

    List query=new ArrayList();
/*    BasicDBObject match=new BasicDBObject("$match",new BasicDBObject("sno",new BasicDBObject("$gt",1)));
    BasicDBObject sort=new BasicDBObject("$sort",new BasicDBObject("sno",1));
    BasicDBObject limit=new BasicDBObject("$limit",1);
    query.add(match);
    query.add(sort);
    query.add(limit);
    AggregateIterable<Document> list= student.aggregate(query);
    long sno=0L;
    for(Document d:list)
    {
        sno=d.getLong("sno");
    }
    */
    Document d= student.find().sort(new Document("sno",-1)).first();
    String sno=d.getString("sno");
    conn.close();

%>


<center>
    <form action="doAdd.jsp" method="post">
    <table border="1px">
        <tr>
            <td>学号</td>
            <td><input type="text" name="sno" value="<%=(Long.parseLong(sno)+1)%>" readonly></td>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input type="text" name="name" id="name"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td>
                <input type="radio" name="sex" value="男" checked>男
                <input type="radio" name="sex" value="女">女
            </td>
        </tr>
        <tr>
            <td>年龄</td>
            <td><input type="number" name="age" id="age"></td>
        </tr>
        <tr>
            <td>身份证号</td>
            <td><input type="text" name="idCard" id="idCard"></td>
        </tr>
        <tr>
            <td>出生日期</td>
            <td><input type="date" name="birthDay" id="birthDat"></td>
        </tr>
        <tr>
            <td>电话号码</td>
            <td><input type="tel" name="phone" id="phone"></td>
        </tr>
        <tr>
            <td>专业</td>
            <td><input type="text" name="major" id="major"></td>
        </tr>
        <tr>
            <td>电子邮箱</td>
            <td><input type="email" name="email" id="email"></td>
        </tr>
        <tr>
            <td>用户名</td>
            <td><input type="text" name="username" id="username"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" name="password" id="password"></td>
        </tr>
        <tr>
            <td>地址</td>
            <td><input type="text" name="address" id="address"></td>
        </tr>

        <tr>
            <td><input type="submit" value="保存"></td>
            <td><input type="reset" value="重置"></td>
        </tr>

    </table>
    </form>
</center>

</body>
</html>
